package com.bolt.admin.module.email.controller;

import com.bolt.admin.logging.annotation.LogAnnotation;
import com.bolt.admin.module.email.dto.EmailConfigDTO;
import com.bolt.admin.module.email.dto.EmailDTO;
import com.bolt.admin.module.email.service.EmailService;
import com.bolt.convention.data.ResultMessage;
import com.bolt.convention.data.Results;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@RestController
@RequiredArgsConstructor
@RequestMapping("api/sys/email")
@Api(tags = "工具：邮件管理")
public class EmailController {

    private final EmailService emailService;


    @GetMapping
    public ResultMessage queryConfig(){
        return Results.success(emailService.findDefault());
    }

    @LogAnnotation(module = "邮件管理", description = "配置邮件")
    @PutMapping
    @ApiOperation("配置邮件")
    public ResultMessage updateConfig(@Validated @RequestBody EmailConfigDTO emailConfig) throws Exception {
        emailService.saveOrUpdate(emailConfig);
        return Results.success();
    }

    @LogAnnotation(module = "邮件管理", description = "发送邮件")
    @PostMapping
    @ApiOperation("发送邮件")
    public ResultMessage sendEmail(@Validated @RequestBody EmailDTO emailDTO){
        emailService.send(emailDTO);
        return Results.success();
    }
}

 